import http from '@/http'
import type { Department, DepartmentQuery, DepartmentForm, PageResult } from './DepartmentModel';

// 获取部门树形结构
export const getDepartmentTree = () => {
  return http.get<Department[]>('/api/department/tree');
};

// 获取部门列表（分页）
export const getDepartmentList = (params: DepartmentQuery) => {
  return http.post<PageResult<Department>>('/api/department/list', params);
};

// 根据父级ID获取下级部门列表（分页）
export const getDepartmentListByParentId = (parentId: number, params: Omit<DepartmentQuery, 'param'> & { param: Omit<DepartmentQuery['param'], 'parentId'> }) => {
  return http.post<PageResult<Department>>(`/api/department/list/${parentId}`, params);
};

// 添加部门
export const addDepartment = (data: DepartmentForm) => {
  return http.post<boolean>('/api/department/add', data);
};

// 更新部门
export const updateDepartment = (data: DepartmentForm) => {
  return http.put<boolean>('/api/department/update', data);
};

// 删除部门
export const deleteDepartment = (id: number) => {
  return http.delete<boolean>(`/api/department/delete/${id}`);
};

// 批量删除部门
export const deleteDepartments = (ids: number[]) => {
  return http.delete<boolean>('/api/department/delete/batch', { data: ids });
};

// 获取部门详情
export const getDepartmentDetail = (id: number) => {
  return http.get<Department>(`/api/department/detail/${id}`);
};
